//
//  CLLScottAlertView.m
//  AnimationRecommend
//
//  Created by 花花蔡 on 2017/2/17.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "CLLScottAlertView.h"

@implementation CLLScottAlertView

/// 背景模糊的alertView
- (void)showEffAlertViewWithTitle:(NSString *)title
                    message:(NSString *)message
                    WithSureBlock:(actionBlock)sure
                    WithCancelBlock:(actionBlock)cancel
                    WithVc:(UIViewController *)vc
    {
        ScottAlertView *alertView = [ScottAlertView alertViewWithTitle:title message:message];
        
        [alertView addAction:[ScottAlertAction actionWithTitle:@"取消" style:ScottAlertActionStyleCancel handler:^(ScottAlertAction *action) {
            cancel(action);
        }]];
        
        [alertView addAction:[ScottAlertAction actionWithTitle:@"确定" style:ScottAlertActionStyleDestructive handler:^(ScottAlertAction *action) {
            sure(action);
            
        }]];

    ScottAlertViewController *alertController = [ScottAlertViewController alertControllerWithAlertView:alertView preferredStyle:ScottAlertControllerStyleAlert transitionAnimationStyle:ScottAlertTransitionStyleFade];
    
    UIImage *img = [UIImage scott_screenShot];
    img = [UIImage scott_blurImage:img blur:0.4];
    
    UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
    imgView.userInteractionEnabled = YES;
    alertController.backgroundView = imgView;
    alertController.tapBackgroundDismissEnable = YES;
    
    [vc presentViewController:alertController animated:YES completion:nil];

    
    }

/// 带有textfield的alertView
- (void)showTextfieldAlertViewWithTitle:(NSString *)title WithMessage:(NSString *)message
                        WithVc:(UIViewController *)vc
                        WithSureBlock:(actionBlock)sure
                        WithCancelBlock:(actionBlock)cancel
                      WithTextFiledText:(void(^)(NSString *text))text
{
    ScottAlertView *alertView = [ScottAlertView alertViewWithTitle:title message:message];
    
    [alertView addAction:[ScottAlertAction actionWithTitle:@"取消" style:ScottAlertActionStyleCancel handler:^(ScottAlertAction *action) {
        //NSLog(@"%@",action.title);
        cancel(action);
    }]];
    
    // 弱引用alertView 否则 会循环引用
    __weak typeof(alertView) weakAlertView = alertView;
    [alertView addAction:[ScottAlertAction actionWithTitle:@"确定" style:ScottAlertActionStyleDestructive handler:^(ScottAlertAction *action) {
        
        //NSLog(@"%@",action.title);
        for (UITextField *textField in weakAlertView.textFieldArray) {
            text(textField.text);
        }

        sure(action);
        
            }]];
    
    [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"请输入昵称";
    }];
    //    [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    //        textField.placeholder = @"请输入密码";
    //    }];
    
    ScottAlertViewController *alertController = [ScottAlertViewController alertControllerWithAlertView:alertView preferredStyle:ScottAlertControllerStyleAlert transitionAnimationStyle:ScottAlertTransitionStyleScaleFade];
    alertController.tapBackgroundDismissEnable = YES;
    
    [vc presentViewController:alertController animated:YES completion:nil];
}


/// 显示在窗口的alertView
- (void)showOnWindowWithTitle:(NSString *)title WithMessage:(NSString *)message {
    ScottAlertView *alertView = [ScottAlertView alertViewWithTitle:title message:
                                 message];
    ScottAlertAction *action = [ScottAlertAction actionWithTitle:@"好的" style:ScottAlertActionStyleDestructive handler:nil];
    [alertView addAction:action];
    
    [ScottShowAlertView showAlertViewWithView:alertView backgroundDismissEnable:YES];
}


//#pragma mark - 清理缓存
///*
// * 1.显示缓存大小
// */
//- (CGFloat)filePath {
//    
//    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
//    return [self folderSizeAtPath:cachPath];
//}
////遍历文件获得文件大小，单位M
//- (CGFloat)folderSizeAtPath:(NSString *)folderPath {
//    
//    NSFileManager *manager = [NSFileManager defaultManager];
//    
//    if (![manager fileExistsAtPath:folderPath]) {
//        return 0;
//    }
//    
//    NSEnumerator *enumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
//    
//    NSString *fileName;
//    NSInteger folderSize = 0;
//    
//    while ((fileName = [enumerator nextObject]) != nil) {
//        NSString *fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
//        folderSize += [self fileSizeAtPath:fileAbsolutePath];
//    }
//    return folderSize / (1024.0 * 1024);
//}
////计算单个文件大小
//- (NSInteger)fileSizeAtPath:(NSString *)filePath {
//    NSFileManager *manager = [NSFileManager defaultManager];
//    
//    if ([manager fileExistsAtPath:filePath]) {
//        return  [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
//    }
//    return 0;
//}
//
//- (void)clearFile {
//    //找到沙盒中存放缓存数据的文件夹路径
//    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
//    
//    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
//    
//    [files enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        //
//        NSError *error = nil;
//        
//        NSString *path = [cachPath stringByAppendingPathComponent:obj];
//        
//        if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
//            [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
//        }
//    }];
//    
//    [self performSelectorOnMainThread:@selector(clearCachSuccess) withObject:nil waitUntilDone:YES];
//}
//
////清理成功
//- (void)clearCachSuccess {
//    
//    [self showOnWindowWithTitle:@"提示" WithMessage:@"清理成功"];
//}




@end
